import { useState, useEffect } from "react"

const useMouse = () => {
  console.log("执行了")
  const [x, setX] = useState(0)
  const [y, setY] = useState(0)

  useEffect(() => {
    const mouseMoveHandler = (event: MouseEvent) => {
      setX(event.clientX)
      setY(event.clientY)
    }
    window.addEventListener("mousemove", mouseMoveHandler)
    return () => {
      console.log("销毁了222")
      window.removeEventListener("mousemove", mouseMoveHandler)
    }
  }, [])

  return { x, y }
}

export default useMouse
